package com.example.madman.yuejian;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.madman.yuejian.Bean.CoachBean;
import com.example.madman.yuejian.IP.IP_Config;
import com.example.madman.yuejian.Listener.RetrofitListener;
import com.example.madman.yuejian.Model.CoachModel;

public class CoachActivity extends AppCompatActivity implements RetrofitListener<CoachBean>{
    private TextView coachname,coachlevel,coachintro;
    private ImageView coach_show,back;
    private IP_Config IPAddress = new IP_Config();
    private int coachid;
    private CoachBean data ;
    private Context context;
    private CoachModel coachModel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coach);
        coachid  = getIntent().getIntExtra("coachid",1);

        initui();
        connecthttp ();

      back.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(CoachActivity.this,MainActivity.class);
              startActivity(intent);
          }
      });
    }



    private void initui(){
        coachname=(TextView)findViewById(R.id.text_coachname);
        coachlevel=(TextView)findViewById(R.id.text_coachlevel);
        coachintro=(TextView)findViewById(R.id.text_coachintro);
        coach_show=(ImageView)findViewById(R.id.dcoach_image);
        back = (ImageView)findViewById(R.id.coach_back);
    }

    private void connecthttp (){
        coachModel = new CoachModel("gson");
        coachModel.getCoachDetail(coachid,this);

    }

    @Override
    public void onSuccess(CoachBean coachBean) {
        data = coachBean;
        coachname.setText(data.getCoachname());
        coachlevel.setText(data.getCoachlevel());
        coachintro.setText(data.getCoachintro());
        Glide.with(this)
                .load(IPAddress.IP+"/yuejian/public/static/assets/img/"+data.getPic())
                .placeholder(R.drawable.club)
                .into(coach_show);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
    }
}
